< previous page page_536 next page >

Page 536
away from the polygon. If any point lies behind the center of projection, this routine sets the IsCulled flag to true, indicating the polygon should not be drawn.
Subroutine NormalVector takes the vector cross-product of the polygon's first two edges to find an outward pointing normal vector. Subroutine Cull uses this subroutine to determine whether the polygon is a backface.
e10a6a0a59f035e870d90cca05b85fce.gif
Private NumPts As Long      ' Number of points.
Private Points() As Point3D ' Data points.

Public IsCulled As Boolean

' Add one or more points to the polygon.
Public Sub AddPoints(ParamArray coord() As Variant)
Dim num_pts As Integer
Dim i As Integer
Dim pt As Integer

    num_pts = (UBound(coord) + 1) \ 3
    ReDim Preserve Points(1 To NumPts + num_pts)

    pt = 0
    For i = 1 To num_pts
        Points(NumPts + i).coord(1) = coord(pt)
        Points(NumPts + i).coord(2) = coord(pt + 1)
        Points(NumPts + i).coord(3) = coord(pt + 2)
        Points(NumPts + i).coord(4) = 1#
        pt = pt + 3
    Next i

    NumPts = NumPts + num_pts
End Sub

' Apply a transformation matrix to the object.
Public Sub Apply(M() As Single)
Dim i As Integer

    ' Do nothing if we are culled.
    If IsCulled Then Exit Sub

    For i = 1 To NumPts 
        m3Apply Points(i).coord, M, Points(i).trans 
    Next i
End Sub

' Cull if any points are behind the center of projection.
Public Sub ClipEye(ByVal R As Single)
Dim pt As Integer

    ' Do nothing if we are already culled.

 
< previous page page_536 next page >